def checkNum(num):
	if len(str(num))!=4: return 0
	nums=[]
	for ch in range(4): nums+=[int(str(num)[ch:ch1]) for ch1 in range(ch+1,5) if not findM(int(str(num)[ch:ch1]))]
	return max(nums) if nums else 0
def findM(num):
	if num==1: return 0
	for i in range(2, num//2+1): 
		if not num%i and findM(i)==0: return i
	return 0
print(checkNum(int(input())))